import { CmdCode } from '../code/index';
import { CmdSignModel, CustomerModel } from '../models';
import { AHttpCmd } from './base.cmd';
import { cacheService } from '../services';
import Taro from '@tarojs/taro';
import { saveToModel } from '../../utils/util';
import { MODEL_person_Info, MODEL_UserId, MODEL_Pwd } from '../../utils/constants';

export class HXRegisterCmd extends AHttpCmd {
    constructor(private model?: any, private reqCode?: string) {
        super();
    }

    req(): CmdSignModel {
        let cmdSign = super.buildCmdSign(this.model, this.reqCode);
        return cmdSign;
    }

    resp(model: CmdSignModel): void {
        if (model.reqCode == "HX_CHATGROUPS_POST") {

        } else {
            let customer: CustomerModel = model.source;
            let modeInfo: any = {
                headImg: customer.avatarUrl
            }
            saveToModel(MODEL_person_Info, modeInfo);
            saveToModel(MODEL_UserId, customer.imUsername);
            saveToModel(MODEL_Pwd, customer.imPassword);
        }
    }

    getCmdCode(): string {
        return CmdCode.EASEMOB_POST;
    }

    getCmdVersion() {
        return '3'
    }
}
